-
Couldn't load subscription status.
- Fork 4
fix: Fix Question Service seed-batch bugs and edge cases #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes synchronization issues in the LeetCode question seeding process by improving cursor management and database operations. It removes the "done" state tracking in favor of more robust pagination handling and optimizes the database schema for better performance.
- Replaces "done" state with total-based cursor management to prevent re-fetching completed data
- Changes from
$setto$setOnInsertto prevent overwriting existing question data - Optimizes database indexes by adding unique constraint on titleSlug and improving compound indexes
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| backend-services/leetcode-backend-service/src/leetcode/seedBatch.ts | Removes done state tracking, improves cursor pagination logic, and changes upsert strategy to preserve existing data |
| backend-services/leetcode-backend-service/src/db/model/question.ts | Adds unique index on titleSlug and optimizes compound indexes for better query performance |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
backend-services/leetcode-backend-service/src/leetcode/seedBatch.ts
Outdated
Show resolved
Hide resolved
| // setOnInsert to avoid overwriting existing entries | ||
| $setOnInsert: { |
Copilot
AI
Oct 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using $setOnInsert instead of $set means that existing questions will never be updated with new data from LeetCode. This could leave stale data in the database if question details change on LeetCode's side.
| // setOnInsert to avoid overwriting existing entries | |
| $setOnInsert: { | |
| // set to update existing entries with latest data | |
| $set: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the intended outcome, not to update the database - to prevent issue where update may overwrite update made manually.
backend-services/leetcode-backend-service/src/db/model/question.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
backend-services/leetcode-backend-service/src/leetcode/seedBatch.ts
Outdated
Show resolved
Hide resolved
| }, | ||
| }, |
Copilot
AI
Oct 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The updatedAt field was removed from $setOnInsert but upsert: true still allows updates. This could lead to inconsistent timestamp behavior for existing records. Consider either adding updatedAt back or clarifying the intended behavior for record updates.
| }, | |
| }, | |
| updatedAt: new Date(), | |
| }, | |
| $set: { | |
| updatedAt: new Date(), | |
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In our case, an additional
$set: {
updatedAt: new Date(),
},
is not required since we only want to insert new records and don't want to update existing ones. Moreover, since the schema already has { timestamps: true }, MongoDB will take care of setting updatedAt when a new document is inserted.
d7a163c to
ceaa880
Compare
ceaa880 to
c970774
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
backend-services/leetcode-backend-service/src/leetcode/seedBatch.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
backend-services/leetcode-backend-service/src/leetcode/seedBatch.ts
Outdated
Show resolved
Hide resolved
| }, | ||
|
|
||
| $setOnInsert: { | ||
| createdAt: new Date(), |
Copilot
AI
Oct 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The createdAt field is set using new Date() which will be the time when the batch operation runs, not when the question was originally created. Consider using a consistent timestamp or the question's actual creation date if available from the LeetCode API.
| createdAt: new Date(), | |
| createdAt: q.createdAt ? new Date(q.createdAt) : new Date(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now, we will keep to the time when the batch operation runs for tracking purposes.
7ae7ebc to
de94690
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Description:
This PR fixes the following issues with the question syncing process:
leetcode-serviceinstead ofquestion-service.Changes Made
leetcode-service.questionsDB